<?php
header("Content-type: text/html; charset=utf-8"); 

//--use database
$mysql_server_name = "localhost";
$mysql_username	= "litianle_fm_man";
$mysql_password = "5228586";
$mysql_database = "litianle_fm_man";

//--connect database
$conn = mysql_connect ($mysql_server_name, $mysql_username , $mysql_password);

//--chose database
mysql_select_db($mysql_database,$conn);

//--set names
mysql_query("set names utf8");

$sid = $_GET['sid'];

$sql = "SELECT `show` FROM `top_man_tmp` WHERE `sid` = $sid;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);

$del_sql = "DELETE FROM `top_man_tmp` WHERE `sid` = $sid";

$s = dirname(__FILE__);
$root = substr_replace("$s",'',-4);
$file = $root.'/show_tmp/'.$row[0];
if($_GET['f'] == 'del')
{
	if(mysql_query($del_sql))
	{
		echo $del_sql."<br>删除成功。";
		if(unlink($file))
		{
			echo "<br><b>图片删除成功！</b>";
		}else{
			echo "<br><b>图片未能删除成功！</b>";
		}
	}else{
		echo "删除不成功!";
	}	
}
if($_GET['f'] =='in')
{
	$sql = "INSERT INTO `top_man` (`name`,`show`,`grade`,`branch`,`mobile`,`qq`,`dateline`) ";
	$sql.= "SELECT `name`,`show`,`grade`,`branch`,`mobile`,`qq`,`dateline` FROM `top_man_tmp` WHERE `sid` = '$sid';";
	if(mysql_query($sql))
	{
		echo ('添加成功！');
		{
			$newfile = $root.'/show/'.$row[0];
			if(copy($file,$newfile))
			{
				echo '成功复制图片到SHOW！';
				unlink($file);
				mysql_query($del_sql);
			}else{
				echo '复制图片失败！';
			}
		}
	}else{
		echo ('添加失败!');
	}
}
echo "<br><a href=\"sh.php\">点击返回继续审核</a>";